package itsm.isperp.module.service.incident;

import itsm.isperp.framework.service.BaseService;
import itsm.isperp.framework.web.request.JqGridFilterRuleOp;
import itsm.isperp.framework.web.request.JqGridRequest;
import itsm.isperp.module.dto.incident.IcdIncidentPropertyDTO;
import itsm.isperp.module.entity.incident.IcdIncidentProperty;
import itsm.isperp.module.repository.incident.IcdIncidentPropertyMapper;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 服务
 * 
 * @author lizx
 * @date 2016-07-21 18:06
 */
@Service
public class IcdIncidentPropertyService extends
		BaseService<IcdIncidentProperty> {

	@Autowired
	protected IcdIncidentPropertyMapper icdIncidentPropertyMapper;

	@Override
	public IcdIncidentPropertyMapper getRepository() {
		return this.icdIncidentPropertyMapper;
	}

	public List<IcdIncidentProperty> findByRelationId(String relationId) {
		return icdIncidentPropertyMapper.findByRelationId(relationId);
	}

	public void deleteByRelationId(String relationId) {
		icdIncidentPropertyMapper.deleteByRelationId(relationId);
	}
	
	public void deleteByRelationIdAndCategoryPropertyId(String relationId,String categoryPropertyId) {
		icdIncidentPropertyMapper.deleteByRelationIdAndCategoryPropertyId(relationId,categoryPropertyId);
	}

	public IcdIncidentProperty findByRelationIdAndPropertyId(String relationId,
			String propertyId) {
		return icdIncidentPropertyMapper.findByRelationIdAndPropertyId(
				relationId, propertyId);
	}

	public List<IcdIncidentProperty> findByRelationIdAndPropertyIds(
			String relationId, String... propertyIds) {
		return icdIncidentPropertyMapper.findByRelationIdAndPropertyIds(
				relationId, propertyIds);
	}

	public List<IcdIncidentProperty> findByRelationIdsAndPropetyId(
			String[] relationIdArr, String propertyId) {
		if (relationIdArr == null || relationIdArr.length == 0) {
			return null;
		}

		return this.icdIncidentPropertyMapper.findByRelationIdsAndPropertyId(
				relationIdArr, propertyId);
	}

	public List<IcdIncidentPropertyDTO> findDatailByRelationId(String relationId) {
		return this.icdIncidentPropertyMapper
				.findDetailByRelationId(relationId);
	}

	public void deleteByRelationIdAndProperties(String relationId,
			List<IcdIncidentProperty> properties) {
		icdIncidentPropertyMapper.deleteByRelationIdAndProperties(relationId,
				properties);
	}

	public List<Map<String,Object>> getProperty(String relationId) {
		JqGridRequest req = new JqGridRequest();
		req.setPageable(false);
		req.addFilterRule("relation_id", JqGridFilterRuleOp.eq, relationId); // 配置项ID
		return icdIncidentPropertyMapper.findAllDetailByRequest(req).getContent();
	}

}
